<template>
  <basic-container>
    <avue-crud
      :option="option"
      :search.sync="search"
      :table-loading="loading"
      :data="data"
      :page.sync="page"
      :permission="permissionList"
      :before-open="beforeOpen"
      v-model="form"
      ref="crud"
      @search-change="searchChange"
      @search-reset="searchReset"
      @selection-change="selectionChange"
      @current-change="currentChange"
      @size-change="sizeChange"
      @refresh-change="refreshChange"
      @sort-change="sortChange"
      @on-load="onLoad"
    >
      <template slot-scope="scope" slot="menu">
        <el-button
          size="small"
          type="info"
          v-if="scope.row.processLv === 1 && scope.row.syncChangeStatus === 1"
          @click.stop="handleEmail(scope.row, scope.index)"
          >补 发</el-button
        >
        <el-button
          size="small"
          :type="isChangeColor(scope.row.isChange, scope.row.uploadStatus)"
          v-if="
            (scope.row.processLv === 0 && scope.row.syncChangeStatus === 0) ||
            scope.row.processLv === -2 ||
            scope.row.processLv === 1
          "
          @click.stop="handleMake(scope.row, scope.index)"
          >{{
            isChangeText(scope.row.isChange, scope.row.uploadStatus)
          }}</el-button
        >
        <el-button
          size="small"
          type="success"
          v-if="scope.row.processLv === 1"
          @click.stop="handleDownload(scope.row, scope.index)"
          >下 载</el-button
        >
        <el-button
          size="small"
          type="danger"
          v-if="scope.row.processLv === 7"
          @click.stop="handleRefund(scope.row, scope.index)"
          >退款红冲</el-button
        >
      </template>
      <template slot="menuRight">
        <el-button type="primary" size="small" plain @click="setTime('今天')"
          >今天
        </el-button>
        <el-button type="primary" size="small" plain @click="setTime('昨天')"
          >昨天
        </el-button>
        <el-button type="primary" size="small" plain @click="setTime('本月')"
          >本月
        </el-button>
        <el-button
          type="warning"
          size="small"
          plain
          icon="el-icon-download"
          @click="handleExport"
          >导出
        </el-button>
      </template>
      <template slot-scope="{}" slot="rpiNoSearch">
        <select-page
          ref="searchRpiSelect"
          label="rpiName"
          value="rpiNo"
          :select.sync="search.rpiNo"
          :url="website.searchLink.merchantUrl"
          placeholder-text="商户"
          filter-key="searchParam"
        ></select-page>
      </template>
      <template slot-scope="{ row }" slot="rptTradeType">
        <span :style="{ color: invoiceWayLabelColor(row.rptTradeType) }">{{
          row.rptTradeTypeName
        }}</span>
      </template>
      <template slot-scope="{ row }" slot="invoiceWay">
        <span :style="{ color: invoiceWayLabelColor(row.invoiceWay) }">{{
          row.invoiceWayName
        }}</span>
      </template>
      <template slot-scope="{ row }" slot="processLv">
        <span :style="{ color: statusColor(row.processLv) }">{{
          row.processLvName
        }}</span>
      </template>
      <template slot-scope="{ row }" slot="uploadStatus">
        <span :style="{ color: uploadStatusColor(row.uploadStatus) }">{{
          row.uploadStatusName
        }}</span>
      </template>
      <template slot-scope="{ row }" slot="rptAmount">
        <span :style="{ color: priceColor }">{{ row.rptAmount }}元</span>
      </template>
    </avue-crud>
    <el-dialog
      class="el-dialog__wrapper avue-dialog avue-crud__dialog"
      :title="isChangeText(invoiceRow.isChange, invoiceRow.uploadStatus)"
      :visible.sync="dialogVisible"
      append-to-body
      :close-on-click-modal="false"
      :before-close="handleClose"
      width="70%"
    >
      <avue-form
        ref="invoiceForm"
        :option="invoiceOption"
        v-model="invoiceForm"
        @submit="invoiceSubmit"
      ></avue-form>
    </el-dialog>
    <el-dialog
      class="el-dialog__wrapper avue-dialog avue-crud__dialog"
      :title="'补发'"
      :visible.sync="dialogemailVisible"
      append-to-body
      :close-on-click-modal="false"
      width="70%"
    >
      <avue-form
        ref="emailForm"
        :option="emailOption"
        v-model="emailForm"
        @submit="emailSubmit"
      ></avue-form>
    </el-dialog>
  </basic-container>
</template>

<script>
import { getList, save, sendInvoice, downloadInvoice, getExport } from "@/api/rb-oem/payinvoice/payinvoice";
import { mapGetters } from "vuex";
import {
  successColor,
  errorColor,
  warningColor,
  infoColor,
  primaryColor,
  purpleColor,
} from "@/util/styles";
import selectPage from "@/components/select-page/select-page";
import { dateFormat } from "@/util/date";
import { downloadBase64Image  } from "@/util/util";

export default {
  components: {
    selectPage,
  },
  data() {
    return {
      form: {},
      query: {},
      search: {},
      loading: false,
      page: {
        pageSize: 10,
        currentPage: 1,
        total: 0,
      },
      selectionList: [],
      option: {
        height: "calc(50vh - 50px)",
        calcHeight: 30,
        tip: false,
        border: true,
        index: true,
        viewBtn: false,
        editBtn: false,
        addBtn: false,
        delBtn: false,
        selection: true,
        searchMenuSpan: 24,
        columnBtn: false,
        labelWidth: 200, //弹出表单的标题的统一宽度
        searchLabelWidth: 110, //搜索框标题宽度
        menuWidth: 300, //操作栏宽度
        emptyBtnText: "重置",
        // searchIcon:true,
        // searchIndex:3,
        column: [
          {
            label: "商户编号",
            searchLabel: "商户名称",
            prop: "rpiNo",
            type: "select",
            searchOrder: 1,
            minWidth: 130,
            search: true,
            overHidden: true,
          },
          {
            label: "通道商户编号",
            prop: "aisleRpiNo",
            type: "input",
            search: true,
            searchOrder: 2,
            minWidth: 100,
          },
          {
            label: "商户名称",
            prop: "rpiName",
            type: "input",
            minWidth: 200,
          },
          {
            label: "订单类型",
            prop: "rptTradeType",
            type: "select",
            dicUrl: "/api/blade-system/dict/dictionary?code=rpt_trade_type",
            props: {
              label: "dictValue",
              value: "dictKey",
            },
            dataType: "string",
            search: true,
            searchOrder: 3,
            minWidth: 100,
            display: false,
            overHidden: true,
          },
          {
            label: "发票类型",
            prop: "invoiceType",
            type: "select",
            dicUrl: "/api/blade-system/dict/dictionary?code=rpt_invoice_type",
            props: {
              label: "dictValue",
              value: "dictKey",
            },
            dataType: "string",
            search: true,
            searchOrder: 4,
            minWidth: 100,
            display: false,
            overHidden: true,
          },
          {
            label: "发票种类",
            prop: "invoiceWay",
            type: "select",
            dicUrl: "/api/blade-system/dict/dictionary?code=invoice_way",
            props: {
              label: "dictValue",
              value: "dictKey",
            },
            dataType: "string",
            search: true,
            searchOrder: 5,
            minWidth: 100,
            display: false,
            overHidden: true,
          },
          {
            label: "开票状态",
            prop: "processLv",
            type: "select",
            dicUrl: "/api/blade-system/dict/dictionary?code=invoice_process_lv",
            props: {
              label: "dictValue",
              value: "dictKey",
            },
            dataType: "string",
            search: true,
            searchOrder: 6,
            minWidth: 100,
            display: false,
            overHidden: true,
          },
          {
            label: "上传状态",
            prop: "uploadStatus",
            type: "select",
            dicUrl:
              "/api/blade-system/dict/dictionary?code=invoice_upload_status",
            props: {
              label: "dictValue",
              value: "dictKey",
            },
            dataType: "string",
            search: true,
            searchOrder: 7,
            minWidth: 100,
            display: false,
            overHidden: true,
          },
          {
            label: "购方名称",
            prop: "taxpayerName",
            type: "input",
            search: true,
            minWidth: 130,
            searchOrder: 9,
          },
          {
            label: "纳税人识别代码",
            prop: "taxpayerNo",
            type: "input",
            search: true,
            overHidden: true,
            minWidth: 160,
            searchOrder: 10,
          },
          {
            label: "是否换开",
            prop: "isChange",
            type: "select",
            dicUrl: "/api/blade-system/dict/dictionary?code=is_change",
            props: {
              label: "dictValue",
              value: "dictKey",
            },
            dataType: "string",
            search: true,
            searchOrder: 8,
            minWidth: 100,
            display: false,
            overHidden: true,
          },
          {
            label: "交易金额",
            prop: "rptAmount",
            type: "input",
            minWidth: 100,
            overHidden: true,
          },
          {
            label: "开票订单编号",
            prop: "outInvoiceId",
            type: "input",
            minWidth: 160,
            search: true,
            overHidden: true,
            searchOrder: 12,
          },
          {
            label: "支付订单编号",
            prop: "rptOrderCode",
            type: "input",
            minWidth: 160,
            search: true,
            overHidden: true,
            searchOrder: 11,
          },
          {
            label: "通道订单编号",
            prop: "rptAisleOrderCode",
            type: "input",
            minWidth: 160,
            search: true,
            overHidden: true,
            searchOrder: 14,
          },
          {
            label: "官方订单编号",
            prop: "rptOtherPayCode",
            type: "input",
            minWidth: 160,
            search: true,
            overHidden: true,
            searchOrder: 13,
          },
          {
            label: "发票号码",
            prop: "invoiceCode",
            type: "input",
            minWidth: 160,
            search: true,
            overHidden: true,
            searchOrder: 15,
          },
          {
            label: "交易日期",
            prop: "rptPayTime",
            type: "input",
            overHidden: true,
            minWidth: 140,
          },
          {
            label: "交易日期",
            prop: "rptPayTimeData",
            type: "datetimerange",
            searchRange: true,
            defaultTime: ["00:00:00", "23:59:59"],
            format: "yyyy-MM-dd HH:mm:ss",
            valueFormat: "yyyy-MM-dd HH:mm:ss",
            startPlaceholder: "开始时间",
            endPlaceholder: "结束时间",
            search: true,
            rules: [
              {
                required: true,
                message: "请选择",
                trigger: "blur",
              },
            ],
            hide: true,
            display: false,
            searchOrder: 16,
          },
          {
            label: "开票日期",
            prop: "invoiceCompleteTime",
            type: "input",
            overHidden: true,
            minWidth: 140,
          },
          {
            label: "开票日期",
            prop: "invoiceCompleteTimeData",
            type: "datetimerange",
            searchRange: true,
            defaultTime: ["00:00:00", "23:59:59"],
            format: "yyyy-MM-dd HH:mm:ss",
            valueFormat: "yyyy-MM-dd HH:mm:ss",
            startPlaceholder: "开始时间",
            endPlaceholder: "结束时间",
            search: true,
            rules: [
              {
                required: true,
                message: "请选择",
                trigger: "blur",
              },
            ],
            hide: true,
            display: false,
            searchOrder: 17,
          },
        ],
      },
      data: [],
      countData: {},
      invoiceRow: {},
      dialogVisible: false,
      invoiceForm: {},
      invoiceOption: {
        calcHeight: 30,
        tip: false,
        border: true,
        index: true,
        refreshBtn: false,
        emptyBtn: false,
        labelWidth: 150,
        column: [
          {
            label: "主键",
            prop: "id",
            type: "input",
            display: false,
            hide: true,
            overHidden: true,
          },
          {
            label: "发票类型",
            prop: "invoiceType",
            type: "select",
            dataType: "string",
            props: {
              label: "dictValue",
              value: "dictKey",
            },
            span: 24,
            minWidth: 150,
            value: "02",
            dicData: [
              {
                dictKey: "02",
                dictValue: "普通发票",
              },
              {
                dictKey: "01",
                dictValue: "专用发票",
              },
            ],
            rules: [
              {
                required: true,
                message: "请选择发票类型",
                trigger: "blur",
              },
            ],
            change: ({ column, value }) => {
              if (value === "02") {
                const buyerPersonType = this.findObject(
                  this.invoiceOption.column,
                  "buyerPersonType"
                );
                buyerPersonType.dicData = [
                  {
                    dictKey: "Y",
                    dictValue: "个人",
                  },
                  {
                    dictKey: "N",
                    dictValue: "企业",
                  },
                ];
                this.invoiceForm.buyerPersonType = "Y";
                const taxpayerAddress = this.findObject(
                  this.invoiceOption.column,
                  "taxpayerAddress"
                );
                taxpayerAddress.rules[0].required = false;
                const taxpayerTelephone = this.findObject(
                  this.invoiceOption.column,
                  "taxpayerTelephone"
                );
                taxpayerTelephone.rules[0].required = false;
                const taxpayerBankCode = this.findObject(
                  this.invoiceOption.column,
                  "taxpayerBankCode"
                );
                taxpayerBankCode.rules[0].required = false;
                const taxpayerAccountNo = this.findObject(
                  this.invoiceOption.column,
                  "taxpayerAccountNo"
                );
                taxpayerAccountNo.rules[0].required = false;
              } else if (value == "01") {
                const buyerPersonType = this.findObject(
                  this.invoiceOption.column,
                  "buyerPersonType"
                );
                buyerPersonType.dicData = [
                  {
                    dictKey: "N",
                    dictValue: "企业",
                  },
                ];
                this.invoiceForm.buyerPersonType = "N";
                const taxpayerAddress = this.findObject(
                  this.invoiceOption.column,
                  "taxpayerAddress"
                );
                taxpayerAddress.rules[0].required = true;
                const taxpayerTelephone = this.findObject(
                  this.invoiceOption.column,
                  "taxpayerTelephone"
                );
                taxpayerTelephone.rules[0].required = true;
                const taxpayerBankCode = this.findObject(
                  this.invoiceOption.column,
                  "taxpayerBankCode"
                );
                taxpayerBankCode.rules[0].required = true;
                const taxpayerAccountNo = this.findObject(
                  this.invoiceOption.column,
                  "taxpayerAccountNo"
                );
                taxpayerAccountNo.rules[0].required = true;
              }
            },
          },
          {
            label: "购方类型",
            prop: "buyerPersonType",
            type: "select",
            dataType: "string",
            props: {
              label: "dictValue",
              value: "dictKey",
            },
            span: 24,
            minWidth: 150,
            value: "Y",
            dicData: [
              {
                dictKey: "Y",
                dictValue: "个人",
              },
              {
                dictKey: "N",
                dictValue: "企业",
              },
            ],
            rules: [
              {
                required: true,
                message: "请选择购方类型",
                trigger: "blur",
              },
            ],
            change: ({ column, value }) => {
              if (value === "Y") {
                const taxpayerType = this.findObject(
                  this.invoiceOption.column,
                  "taxpayerType"
                );
                taxpayerType.display = true;
                const taxpayerNo = this.findObject(
                  this.invoiceOption.column,
                  "taxpayerNo"
                );
                taxpayerNo.label = "证件号码";
                const taxpayerAddress = this.findObject(
                  this.invoiceOption.column,
                  "taxpayerAddress"
                );
                taxpayerAddress.display = false;
                const taxpayerTelephone = this.findObject(
                  this.invoiceOption.column,
                  "taxpayerTelephone"
                );
                taxpayerTelephone.display = false;
                const taxpayerBankCode = this.findObject(
                  this.invoiceOption.column,
                  "taxpayerBankCode"
                );
                taxpayerBankCode.display = false;
                const taxpayerAccountNo = this.findObject(
                  this.invoiceOption.column,
                  "taxpayerAccountNo"
                );
                taxpayerAccountNo.display = false;
              } else if (value === "N") {
                const taxpayerType = this.findObject(
                  this.invoiceOption.column,
                  "taxpayerType"
                );
                taxpayerType.display = false;
                const taxpayerNo = this.findObject(
                  this.invoiceOption.column,
                  "taxpayerNo"
                );
                taxpayerNo.label = "纳税人识别号";
                const taxpayerAddress = this.findObject(
                  this.invoiceOption.column,
                  "taxpayerAddress"
                );
                taxpayerAddress.display = true;
                const taxpayerTelephone = this.findObject(
                  this.invoiceOption.column,
                  "taxpayerTelephone"
                );
                taxpayerTelephone.display = true;
                const taxpayerBankCode = this.findObject(
                  this.invoiceOption.column,
                  "taxpayerBankCode"
                );
                taxpayerBankCode.display = true;
                const taxpayerAccountNo = this.findObject(
                  this.invoiceOption.column,
                  "taxpayerAccountNo"
                );
                taxpayerAccountNo.display = true;
              }
            },
          },
          {
            label: "发票抬头",
            prop: "taxpayerName",
            type: "input",
            minWidth: 150,
            span: 24,
            rules: [
              {
                required: true,
                message: "请输入发票抬头",
                trigger: "blur",
              },
            ],
            overHidden: true,
          },
          {
            label: "证件类型",
            prop: "taxpayerType",
            type: "select",
            dataType: "number",
            props: {
              label: "dictValue",
              value: "dictKey",
            },
            span: 24,
            // search: true,
            dicUrl: "/api/blade-system/dict/dictionary?code=id_type",
            minWidth: 150,
            value: 1,
            display: true,
            rules: [
              {
                required: true,
                message: "请选择证件类型",
                trigger: "blur",
              },
            ],
          },
          {
            label: "纳税人识别号",
            prop: "taxpayerNo",
            type: "input",
            minWidth: 150,
            span: 24,
            display: true,
            rules: [
              {
                required: true,
                message: "请输入纳税人识别号",
                trigger: "blur",
              },
            ],
            overHidden: true,
          },
          {
            label: "注册地址",
            prop: "taxpayerAddress",
            type: "input",
            minWidth: 150,
            span: 24,
            display: true,
            rules: [
              {
                required: true,
                message: "请输入注册地址",
                trigger: "blur",
              },
            ],
            overHidden: true,
          },
          {
            label: "注册电话",
            prop: "taxpayerTelephone",
            type: "number",
            minWidth: 150,
            span: 24,
            display: true,
            rules: [
              {
                required: true,
                message: "请输入注册电话",
                trigger: "blur",
              },
            ],
            overHidden: true,
          },
          {
            label: "开户银行",
            prop: "taxpayerBankCode",
            type: "input",
            minWidth: 150,
            span: 24,
            display: true,
            rules: [
              {
                required: true,
                message: "请输入开户银行",
                trigger: "blur",
              },
            ],
            overHidden: true,
          },
          {
            label: "银行账号",
            prop: "taxpayerAccountNo",
            type: "number",
            minWidth: 150,
            span: 24,
            display: true,
            rules: [
              {
                required: true,
                message: "请输入银行账号",
                trigger: "blur",
              },
            ],
            overHidden: true,
          },
          {
            label: "收票邮箱",
            prop: "email",
            type: "input",
            minWidth: 150,
            span: 24,
            overHidden: true,
          },
        ],
      },
      dialogemailVisible: false,
      emailOption: {
        calcHeight: 30,
        tip: false,
        border: true,
        index: true,
        refreshBtn: false,
        emptyBtn: false,
        labelWidth: 150,
        column: [
          {
            label: "收票邮箱",
            prop: "email",
            type: "input",
            minWidth: 150,
            span: 24,
            overHidden: true,
          },
        ],
      },
      emailForm: {},
    };
  },
  computed: {
    ...mapGetters(["permission"]),
    ids() {
      let ids = [];
      this.selectionList.forEach((ele) => {
        ids.push(ele.id);
      });
      return ids.join(",");
    },
    exhibition() {
      return (val) => {
        if (val == "" || val == "-1") {
          return (val = 0);
        } else {
          return val;
        }
      };
    },
    priceColor() {
      return errorColor;
    },
    statusColor() {
      return (status) => {
        return status == 1 ? successColor : errorColor;
      };
    },
    invoiceWayLabelColor() {
      return (status) => {
        return status == 1 ? primaryColor : errorColor;
      };
    },
    uploadStatusColor() {
      return (state) => {
        if (state === "00") {
          return infoColor;
        } else if (state === "01") {
          return purpleColor;
        } else if (state === "02") {
          return purpleColor;
        } else if (state === "03") {
          return warningColor;
        } else if (state === "04") {
          return successColor;
        } else if (state === "05") {
          return errorColor;
        } else {
          return infoColor;
        }
      };
    },
    isChangeText() {
      return (state, status) => {
        let text = "";
        if (status === "05") {
          text = "重开发票";
        } else {
          if (state == 0) {
            text = "开票";
          } else if (state == 1) {
            text = "重开发票";
          }
        }
        return text;
      };
    },
    isChangeColor() {
      return (state, status) => {
        let text = "";
        if (status === "05") {
          text = "danger";
        } else {
          if (state == 0) {
            text = "primary";
          } else if (state == 1) {
            text = "danger";
          }
        }
        return text;
      };
    },
  },
  watch: {
    "search.rptPayTimeData"(val) {
      if (val) {
        this.search.rptPayTimeBegin = val[0];
        this.search.rptPayTimeEnd = val[1];
      } else {
        this.search.rptPayTimeBegin = "";
        this.search.rptPayTimeEnd = "";
      }
    },
    "search.invoiceCompleteTimeData"(val) {
      if (val) {
        this.search.invoiceCompleteTimeBegin = val[0];
        this.search.invoiceCompleteTimeEnd = val[1];
      } else {
        this.search.invoiceCompleteTimeBegin = "";
        this.search.invoiceCompleteTimeEnd = "";
      }
    },
  },
  methods: {
    invoiceSubmit(row) {
      save({ ...this.invoiceRow, ...row }).then(
        () => {
          this.onLoad(this.page);
          this.dialogVisible = false;
          this.$message({
            type: "success",
            message: "操作成功!",
          });
        },
        (error) => {
          window.console.log(error);
          this.dialogVisible = false;
        }
      );
    },
    emailSubmit(row) {
      sendInvoice({
        ...this.emailRow,
        ...row,
        rpiNo: this.selectMer.rpiNo,
      }).then(
        () => {
          this.onLoad(this.page);
          this.dialogemailVisible = false;
          this.$message({
            type: "success",
            message: "操作成功!",
          });
        },
        (error) => {
          window.console.log(error);
          this.dialogemailVisible = false;
        }
      );
    },
    handleEmail(row) { 
      this.emailRow = row;
      this.dialogemailVisible = true;
    },
    // 下载文件
    handleDownload(row) {
      this.$confirm("是否下载文件?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(() => {
        downloadInvoice(row.rptOrderCode).then((res) =>{
          // window.open('data:image/png;base64,' + res.data.data);
          let url = 'data:image/png;base64,' + res.data.data;
          downloadBase64Image(url, `${row.rpiName}_${row.rptOrderCode}`, 'image/png');
          // invoiceCode
          // this.refreshChange();
        })
      });
    },
    handleMake(row) {
      this.invoiceRow = row;
      this.dialogVisible = true;
    },
    /**
     * @func 详情
     * @desc 点击详情进入详情界面
     * @param {Object} row - 商户信息
     * */
    handleDetail(row) {
      this.$router.push({
        name: "交易详情",
        query: {
          rptAisleOrderCode: row.rptAisleOrderCode,
        },
      });
    },
    handleRefund(row) {
      this.$router.push({
        name: "开票详情",
        query: {
          rptAisleOrderCode: row.rptAisleOrderCode,
        },
      });
    },
    /**
     * @func edit,view 打开之前回调
     * @desc 点击获取点击天数时间
     * */
    beforeOpen(done, type) {
      if (["edit", "view"].includes(type)) {
        // getDetail(this.form.id).then(res => {
        //   this.form = res.data.data;
        // });
      }
      done();
    },
    /**
     * @func 重置
     * @desc 重置查询条件
     * */
    searchReset() {
      this.query = {};
      this.search = {};
      this.$set(this.search, "rptPayTimeData", ["", ""]);
      this.$set(this.search, "invoiceCompleteTimeData", ["", ""]);
      this.onLoad(this.page);
    },
    /**
     * @func 搜索
     * @desc 根据条件查询
     * @param {params} params --- 条件查询
     * */
    searchChange(params, done) {
      this.query = params;
      this.page.currentPage = 1;
      this.onLoad(this.page, params);
      done();
    },
    /**
     * @func 选中单元格
     * @desc 选中单元格数据
     * @param {list} list --- 选中单元格数据-数组
     * */
    selectionChange(list) {
      this.selectionList = list;
    },
    selectionClear() {
      this.selectionList = [];
      this.$refs.crud.toggleSelection();
    },
    /**
     * @func 分页页码
     * @desc 分页页码改变时会触发
     * */
    currentChange(currentPage) {
      this.page.currentPage = currentPage;
      // this.refreshChange();
    },
    /**
     * @func 当前页个数
     * @desc pageSize改变时会触发
     * */
    sizeChange(pageSize) {
      this.page.pageSize = pageSize;
      // this.refreshChange();
    },
    /**
     * @func 刷新
     * @desc 点击刷新按钮触发该事件
     * */
    refreshChange() {
      this.onLoad(this.page, this.query);
    },
    /**
     * @func 初始化
     * @desc 表格初始化查询数据
     * */
    onLoad(page, params = {}) {
      this.loading = true;
      // if(this.query.isSelectChildArr){
      //   this.query.isSelectChild = this.query.isSelectChildArr[0];
      // }
      getList(
        page.currentPage,
        page.pageSize,
        Object.assign(params, this.query)
      ).then((res) => {
        const data = res.data.data;
        this.page.total = data.total;
        this.data = data.records;
        this.loading = false;
        this.selectionClear();
      });
    },
    setTime(type) {
      let date = new Date();
      this.query = {};
      if (type == "今天") {
        this.search.invoiceCompleteTimeBegin =
          dateFormat(date, "yyyy-MM-dd") + " 00:00:00";
        this.search.invoiceCompleteTimeEnd =
          dateFormat(date, "yyyy-MM-dd") + " 23:59:59";
      } else if (type == "昨天") {
        this.search.invoiceCompleteTimeBegin =
          dateFormat(
            new Date(date.getTime() - 3600 * 1000 * 24 * 1),
            "yyyy-MM-dd"
          ) + " 00:00:00";
        this.search.invoiceCompleteTimeEnd =
          dateFormat(
            new Date(date.getTime() - 3600 * 1000 * 24 * 1),
            "yyyy-MM-dd"
          ) + " 23:59:59";
      } else if (type == "本月") {
        // "本月"
        this.search.invoiceCompleteTimeBegin =
          dateFormat(date, "yyyy-MM") + "-01 00:00:00";
        this.search.invoiceCompleteTimeEnd =
          dateFormat(date, "yyyy-MM-dd") + " 23:59:59";
      }
      this.search.invoiceCompleteTimeData = [
        this.search.invoiceCompleteTimeBegin,
        this.search.invoiceCompleteTimeEnd,
      ];
      this.page.currentPage = 1;
      this.forInSearch();
      this.onLoad(this.page, this.query);
    },
    forInSearch() {
      for (let key in this.search) {
        if (this.search[key]) {
          if (key.indexOf("$") == -1) {
            this.query[key] = this.search[key];
          }
        }
      }
    },
    /**
     * @func 导出
     * @desc 根据条件导出
     * */
    handleExport() {
      let params = {
        ...this.search,
        current: "-1",
        size: "-1",
      };

      this.$confirm("是否导出?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      }).then(() => {
        getExport(params).then(
          (res) => {
            this.$message({
              type: "success",
              message: res.data.msg,
            });
          },
          (error) => {
            window.console.log(error);
          }
        );
      });
    },
    /**
     * @func 排序
     * @desc 根据表格字段排序
     * */
    sortChange(val) {
      if (val.order == "ascending") {
        //正序
        this.query.ascs = val.prop;
        this.query.descs = "";
      } else {
        //倒序
        this.query.descs = val.prop;
        this.query.ascs = "";
      }
      this.refreshChange();
    },
  },
};
</script>

<style lang="scss" scoped>
.curd-foter {
  padding-top: 10px;
  display: flex;
  flex-wrap: wrap;
}

.redFontBox {
  margin-right: 40px;
  .redFont {
    color: red;
  }
}
/deep/ .el-tag--dark.el-tag--success {
  border: none !important;
}
</style>
